Skip to content

Treat no-op git commit (nothing to commit) as a skip, not a failure - #26

Merged
neilvcarvalho merged 1 commit into
thoughtbot:mainfrom
elalemanyo:fix/treat-nothing-to-commit-as-skip
Aug 3, 2026
Merged

Treat no-op git commit (nothing to commit) as a skip, not a failure#26
neilvcarvalho merged 1 commit into
thoughtbot:mainfrom
elalemanyo:fix/treat-nothing-to-commit-as-skip

Conversation

@elalemanyo

Copy link
Copy Markdown
Contributor

Problem

The action failed on repos where bin/importmap pin produced no changes,
with all planned PRs reporting a hard failure:

  • open failed importmap-updates/major-maplibre-gl PR# — git commit ..., status: exit 1, stderr: ""

Root cause

When bin/importmap pin <pkg>@<version> results in no diff (the package
is already at that version), git commit exits with code 1 and writes:

# On branch main
nothing to commit, working tree clean

That message is emitted on stdout, not stderr. But
GitClient#commit_changes only inspected e.result.stderr to detect
this benign case:

rescue Git::FailedError => e
  return false if e.result.stderr.to_s.include?("nothing to commit")
  raise
end

Since stderr was empty, the check never matched, the error was
re-raised, and the action exited 1 — even though there was nothing
wrong, just nothing to commit.

Fix

lib/git_client.rb now checks both stdout and stderr for the
"nothing to commit" marker, so a no-op pin is correctly treated as a
skip ("No changes after pinning") instead of a failure.

rescue Git::FailedError => e
  return false if "#{e.result.stdout} #{e.result.stderr}".include?("nothing to commit")
  raise
end

Test plan

  • Added regression test test_commit_changes_returns_false_when_nothing_to_commit_on_stdout
    covering the real git behavior (message on stdout, empty stderr).

@neilvcarvalho

Copy link
Copy Markdown
Member

Thank you! We plan to release this action in the GitHub Marketplace and in the thoughtbot blog in the next few days, wrapping up a 1.0 version. I failed to find a project using importmap extensively after I left my previous project and ended up not touching this action (also some long PTO). I appreciate you using it, finding bugs and opening PRs to fix them.

@neilvcarvalho
neilvcarvalho merged commit 0de4dea into thoughtbot:main Aug 3, 2026
6 checks passed
@elalemanyo
elalemanyo deleted the fix/treat-nothing-to-commit-as-skip branch August 3, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants